<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text">
  <button class="cancel">取消</button>

  <script src="./js/hy_debounce.js"></script>
  
  <script>
    const inputEl = document.querySelector("input")
    const cancelBtn = document.querySelector(".cancel")

    let counter = 1
    const debounceFn = hydebounce(function (event) {
      console.log(`发送网络请求${counter++}:`, this, event)
    }, 1000)
    inputEl.oninput = debounceFn

    // 4.实现取消的功能
    cancelBtn.onclick = function () {
      debounceFn.cancel()
    }
  </script>
</body>

</html>